<template>
  <el-card style="margin-bottom:20px;">
    <div slot="header" class="clearfix">
      <span>About me</span>
    </div>

    <div class="user-profile">
      <div class="box-center">
        <pan-thumb :image="avatar" :height="'100px'" :width="'100px'" :hoverable="false">

          <vab-upload ref="vabUpload" :limit="50" name="file" :size="2" url="/upload"></vab-upload>
          <el-button type="primary" class="elbutton" @click="handleShow({ key: 'value' })" plain>更改头像</el-button>
        </pan-thumb>
      </div>
      <div class="box-center">
        <!-- <div class="user-name text-center">{{ user.name }}</div> -->
        <div class="user-name text-center">{{ yx.username }}</div>
        <!-- <div class="user-role text-center text-muted">{{ user.role | uppercaseFirst }}</div> -->
        <div class="user-role text-center text-muted">{{ yx.role | uppercaseFirst }}</div>
      </div>
    </div>

    <!-- <div class="user-bio">
      <div class="user-education user-bio-section">
        <div class="user-bio-section-header"><svg-icon icon-class="education" /><span>Education</span></div>
        <div class="user-bio-section-body">
          <div class="text-muted">
            JS in Computer Science from the University of Technology
          </div>
        </div>
      </div> -->


    <!-- 用户email -->
    <div class="user-bio">
      <div class="user-education user-bio-section">
        <div class="user-bio-section-header"><span>email</span></div>
        <div class="user-bio-section-body">
          <!-- <div class="text-muted"> {{ user.email }}</div> -->
          <div class="text-muted"> {{ yx.email }}</div>
        </div>
      </div>
    </div>


    <div class="user-bio">
      <div class="user-education user-bio-section">
        <div class="user-bio-section-header"><span>phone</span></div>
        <div class="user-bio-section-body">
          <!-- <div class="text-muted"> {{ user.phone }}</div> -->
          <div class="text-muted"> {{ yx.phone }}</div>
        </div>
      </div>



      <div class="user-skills user-bio-section">
        <div class="user-bio-section-header"><span>introduction</span></div>
        <div class="user-bio-section-body">
          <!-- <div class="text-muted"> {{ user.introduction }}</div> -->
          <div class="text-muted"> {{ yx.introduction }}</div>

        </div>
      </div>
    </div>
  </el-card>
</template>

<script>
import { mapGetters } from 'vuex'
import PanThumb from '@/components/PanThumb'
import VabUpload from '@/components/VabUpload'
import { senduser, sendquery } from '@/api/form'
export default {

  components: { PanThumb, VabUpload },
  props: {
    user: {
      type: Object,
      default: () => {
        return {
          name: '',
          email: '',
          avatar: '',
          role: '',
          phone: '',
          introduction: ''
        }
      }
    }
  },
  data () {
    return {
      //向后端发送的内容
      yx: {
        username: '',
        password: '',
        phone: '',
        email: '',
        introduction: '',
        role: '',
      },
      avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif'
    }
  },
  created () {
    this.fetchdata()
  },
  computed: {
    ...mapGetters([
      'name',
      'avatar',
      'roles'
    ])
  },
  methods: {
    fetchdata () {
      sendquery(this.iu).then(response => {
        // 处理成功的响应
        this.yx.introduction = response.data["introduction"]
        this.yx.username = response.data["name"]
        this.yx.role = response.data["roles"]
        this.yx.phone = response.data["phone"]
        this.yx.email = response.data["email"]
        this.$message('usercard update successfully!')
        // reponsecode = reponse.data["code"]
      }).catch(error => {
        // 处理错误的响应
        this.$message.error('Failed to update usercard')
      })
    },
    handleShow (data) {
      this.$refs['vabUpload'].handleShow(data)
    }
  }
}
</script>

<style lang="scss" scoped>
.elbutton {
  margin-top: 30%;
  width: 60px;
  height: 30px;
  padding: 0;
  font-size: 12px;
}

.box-center {
  margin: 0 auto;
  display: table;
}

.text-muted {
  color: #777;
}

.user-profile {
  .user-name {
    font-weight: bold;
  }

  .box-center {
    padding-top: 10px;
  }

  .user-role {
    padding-top: 10px;
    font-weight: 400;
    font-size: 14px;
  }

  .box-social {
    padding-top: 30px;

    .el-table {
      border-top: 1px solid #dfe6ec;
    }
  }

  .user-follow {
    padding-top: 20px;
  }
}

.user-bio {
  margin-top: 20px;
  color: #606266;

  span {
    padding-left: 4px;
  }

  .user-bio-section {
    font-size: 14px;
    padding: 15px 0;

    .user-bio-section-header {
      border-bottom: 1px solid #dfe6ec;
      padding-bottom: 10px;
      margin-bottom: 10px;
      font-weight: bold;
    }
  }
}
</style>
